//
//  TableEmployee.m
//  NursingManages
//
//  Created by HuangZhen on 2017/5/26.
//  Copyright © 2017年 huangzhen. All rights reserved.
//


#import "TableEmployee.h"



@implementation TableEmployee

-(NSMutableArray *) TransalteToModel:(FMResultSet*) set{

    NSMutableArray *array = [NSMutableArray array];
    while ([set next]) {
        Model_Pub_Employee *model = [[Model_Pub_Employee alloc]init];
        model.EMP_NAME = [set stringForColumn:@"empt_name"];
        model.JUB_NUM = [set stringForColumn:@"jub_num"];
        model.INPUT_CODE1 = [set stringForColumn:@"input_code1"];
        model.DEPT_NAME = [set stringForColumn:@"dept_name"];
        model.ADDRESS = [set stringForColumn:@"address"];
        model.EMP_ID = [set stringForColumn:@"emp_id"];
        model.MOBILE_PHONE = [set stringForColumn:@"mobile_phone"];
        model.DEPT_ID1 = [set stringForColumn:@"detp_id1"];
        model.DEPT_ID6 = [set stringForColumn:@"dept_id6"];
        model.DEPT_NAME6 = [set stringForColumn:@"dept_name6"];
        
        if(model.INPUT_CODE1 == nil){
            model.INPUT_CODE1 = @"#";
        }
        model.INPUT_CODE1 = [model.INPUT_CODE1 uppercaseString];
        
        [array addObject:model];
    }
    
    return array;
}


- (NSMutableArray *)GetEmpolyee {
    [DBHelper.DB open];
    NSMutableArray *array = [NSMutableArray new];
    array = [self GetEmpolyeeWithInputCode:@""];
    [DBHelper.DB close];
    return array;

}
- (NSMutableArray *)GetEmpolyeeWithInputCode:(NSString *)input_code {
    
    [DBHelper.DB open];
    
    NSString* sql = @"select * from pub_employee where 1 = 1 %@";
    
    NSString *where = @"";
    
    if (![input_code  isEqual: @""]){
        where = [NSString stringWithFormat:@" and input_code1 like '%@%@'",input_code,@"%"];
    }
    sql = [NSString stringWithFormat:sql,where];
    NSString *order = @" %@ order by input_code1 asc";
    
    sql = [NSString stringWithFormat:order,sql];
    
    FMResultSet *set = [DBHelper.DB executeQuery:sql];
    NSMutableArray *array = [self TransalteToModel:set];
 

    [DBHelper.DB close];
    return array;

    
}


-(Model_Pub_Employee *) GetModelWithEmpId:(NSString *)EMP_ID{
    [DBHelper.DB open];
    
    NSString* sql = @"select * from pub_employee where emp_id = '%@'";

    sql = [NSString stringWithFormat:sql,EMP_ID];
    
    Model_Pub_Employee *rets = [[Model_Pub_Employee alloc]init];
    rets.EMP_ID = @"";
    rets.EMP_NAME = @"未登录";
    
    FMResultSet *set = [DBHelper.DB executeQuery:sql];
    NSMutableArray *array = [self TransalteToModel:set];
    
    [DBHelper.DB close];
    
    
    
    if (array.count != 0) {
        return array[0];
    }
    
    
    return [[Model_Pub_Employee alloc]init];
}

@end
